<template>
	<view>
		<u-calendar @getlist="getlist" :timeAll="timeAll" ref="child2Container" @funclti="clikcTime" v-model="show"
			:mode="mode" @change="change"></u-calendar>
		<!-- <bot-item :nowtiem="nowtiem"></bot-item> -->

		<bot-item :ymm="ymm" :dymzt="dymzt" :tfal="tfal" :today="today" @great="great" :clicktime="clicktime">
		</bot-item>
	</view>
</template>

<script>
	import botItem from './components/bot.vue';
	import api from '@/api/fetation.js';

	export default {
		components: {
			botItem
		},
		data() {
			return {
				dymzt: 0, //状态  //状态 2来了-关 1走了-开
				clicktime: '', //选中时间
				show: true,
				mode: 'range',
				openid: '',
				today: '',
				timeAll: '',
				arrAllTime: '', //自己点的5天
				tfal: '', //判断同房按钮开关 1有数据开起  2没有数据关
				ymm: '',
				arrtime: [],
			};
		},
		onLoad() {
			this.openid = uni.getStorageSync('openid');
			this.getime();
		},

		onShow: function() {
			this.openid = uni.getStorageSync('openid');
			this.getlist();
		},

		watch: {
			dymzt: function(newData) {

				this.dymzt = newData;
				deep: true;
			},
			
			timeAll: function(newData) {
			
				this.timeAll = newData;
				deep: true;
			}
		},

		methods: {
			great(status) {
				this.$refs.child2Container.chenClick(status);
			},
			//获取列表数据
			async getlist() {
				var arr = {
					openid: this.openid,
					time: this.clicktime
				};
				const {
					data
				} = await api.getList(arr);
				this.today = data.today;
				this.timeAll = data.data;
				//判断同房按钮开关 1有数据开起  2没有数据关
				if (!data.today) {
					this.tfal = 2
				} else {
					if (data.today.tf_record_title) {
						this.tfal = 1
					} else {
						this.tfal = 2
					}

				}


				var arrln = [];
				this.timeAll.forEach(function(value) {
					arrln.push(value.time);
				});
				this.arrtime = arrln
				console.log('后台返回天数集合', arrln);
			},
			getime() {
				var date = new Date();
				var year = date.getFullYear(); //年
				var month = date.getMonth() + 1; //月
				var day = date.getDate(); //日
				this.clicktime = year + '-' + month + '-' + day;
			},
			//子组件点击获取
			async clikcTime(data) {
				// this.dymzt = ''
				this.clicktime = data.date;
				// this.dymzt = data.dymzt;

				var arr = {
					openid: this.openid,
					time: this.clicktime
				};
				var arrlet = await api.getList(arr)




				this.today = arrlet.data.today
				this.timeAll = arrlet.data.data;

				console.log(arrlet.data.today)
				console.log('index点击时间',this.timeAll)

				var arrln = [];
				this.timeAll.forEach(function(value) {
					arrln.push(value.time);
				});
				this.arrtime = arrln
				


				var arrin = this.arrtime.includes(this.clicktime); // 选择时间是否在以前数组中
				console.log('选中时间是否在后台时间里+点击一个日期arrin', arrin)
				console.log('后台时间+点击一个日期index', this.arrtime)
				console.log('选中时间+点击一个日期index', this.clicktime)
				//状态 2来了-关 1走了-开
				if (arrin) {
					this.dymzt = 1
				} else {
					this.dymzt = 2
				}

				console.log('选中时间', this.clicktime);
				//状态 2来了-关 1走了-开
				console.log('父组件 1开来了,2关-走了', this.dymzt);
				//ym 1是开起 2关闭
				var arrin = this.arrtime.includes(this.clicktime);
				console.log(arrin)
				console.log(this.arrtime)
				if (arrin) {
					this.ymm = 1
				} else {
					this.ymm = 2
				}
			},
			change(e) {
				console.log('666');
				console.log(e);
			}
		}
	};
</script>
